#!/usr/bin/python



from xpcom import *
import sys


from ontology_manager import OntologyManager

import logging
logger = logging.getLogger("the_nepomuk_whisperer")


"""
This class is the entry point for the XUL pages. It provides some constants (NAO, PIMO) that will be used by the XUL pages to call the methods from one ontology or the other.
"""

class TheNepomukWhisperer(object): # Inherits from object, necessary for the Singleton Design Pattern.
	
	#~~~~~~~~~~~~~~~~~~~~~~~~~ BEGIN  ~~~~~~~~~~~~~~~~~~~~~~~~~#
	
	#~ This is the Python code for an advanced Singleton Design Pattern use. ~#
	#~ see http://en.wikipedia.org/wiki/Singleton_pattern#Python for more information (available on the 2008-07-07). ~#
	#~ If you want to inherit from TheNepomukWhisperer, you should study the subject and possibly rewrite it (see the same web page for details on inheritance). ~#
	
	# static attributes of the class Interface
	instance = None
	
	# standard construction method in Python
	def __new__(theNepomukWhispererClass, ontologies_storage_file=None, service_name="org.kde.NepomukStorage", model_name="/org/soprano/Server/models/main"):
		"""
			:Parameters:
				`ontologies_storage_file` : str
					The path to a file where the ontologies selected by the user are stored.
				`service_name` : str
					The name of the service that is to be called for storage purpose (mainly adding/retrieval of statements, querying).
				`model_name` : str
					The dbus path to the soprano model that we are going to work on.
			:Raises `dbus.exceptions.DBusException`: if the service_name is not accessible (exception raised by python_interface_to_soprano.py).
		"""
		
		logger.debug("TheNepomukWhisperer.__new__")
		if theNepomukWhispererClass.instance is None:
			
			# initializations (run only once)
			logger.debug("\t(first time)")
			
			self_obj = object.__new__(theNepomukWhispererClass)
			theNepomukWhispererClass.instance = self_obj
			
			# interface
			from python_interface_to_soprano import Interface
			self_obj.interface = Interface(service_name, model_name)
			
			# nao
			from nao import Nao
			self_obj.nao = Nao(self_obj.interface)
			
			#pimo
			from pimo import Pimo
			self_obj.pimo = Pimo(self_obj.interface)
			
		return theNepomukWhispererClass.instance
	
	#~~~~~~~~~~~~~~~~~~~~~~~~~  END   ~~~~~~~~~~~~~~~~~~~~~~~~~#
	
	
	def __init__(self, ontologies_storage_file=None, service_name="org.kde.NepomukStorage", model_name="/org/soprano/Server/models/main"):
		
		logger.debug("TheNepomukWhisperer.__init__")
		
		# ontology manager
		self.ontos_mgr = OntologyManager(self.interface, ontologies_storage_file)







logger.debug("the_nepomuk_whisperer.py has been imported")
